#ifndef CURRENTITEMOBSERVER_H
#define CURRENTITEMOBSERVER_H

#include <QObject>
#include <QUuid>
#include <QTextDocument>
#include <QItemSelectionModel>
#include <QFont>

//#include "knowledgenodeedit.h"
#include "treemodel.h"

class CurrentItemObserver : public QObject
{
		Q_OBJECT
		//Q_PROPERTY(QTextDocument* question READ question WRITE setQuestion NOTIFY questionChanged)
		//Q_PROPERTY(QTextDocument* answer READ answer WRITE setAnswer NOTIFY answerChanged)



	public:
		explicit				CurrentItemObserver(QObject *parent = 0);

		QString					imageResourceName() const;
		void					setImageResourceName(const QString&);

		QTextDocument*			question() const;
		QTextDocument*			answer() const;

		QFont					defaultFont() const;

		void					bindTo(TreeModel* pModel, QItemSelectionModel* pSelectionModel);

	signals:

		void					questionChanged(QTextDocument* value);
		void					answerChanged(QTextDocument* value);

	public slots:

		void					questionToModel();
		void					answerToModel();

		void					setDefaultFont(QFont font);

	private slots:

		void					onCurrentChanged(const QModelIndex &current, const QModelIndex &previous);
		void					onModelTreeItemChanged(const TreeItem& item);
		void					onNewTreeCreated();

	private:

		void					updateFields(const QModelIndex& current);

	private:

		QString 				m_imageResourceName;

		TreeModel* 				m_pModel;
		QItemSelectionModel* 	m_pSelectionModel;

		QTextDocument* 			m_pQuestion;
		QTextDocument* 			m_pAnswer;
		
		//we could store TreeItem instead but in that case we would have to observe
		//whether the item was destroyed by the model to avoid dead pointers
		QUuid 					m_currentItemUuid; 
		QFont					m_defaultFont;

};

#endif // CURRENTITEMOBSERVER_H
